From 54717da9f94e7431fc929523218c64135a2dc49e Mon Sep 17 00:00:00 2001 From: Gabriel Wicke Date: Sat, 10 Apr 2004 15:11:14 +0000 Subject: [PATCH] paragraphs again, amp matching moved to match stripped areas as well --- includes/Parser.php | 82 +++++++++++++++++++++++++++------------------ 1 file changed, 50 insertions(+), 32 deletions(-) diff --git a/includes/Parser.php b/includes/Parser.php index 5d0aa976a2..3f64232eb5 100644 --- a/includes/Parser.php +++ b/includes/Parser.php @@ -93,6 +93,17 @@ class Parser $text = $this->strip( $text, $this->mStripState ); $text = $this->doWikiPass2( $text, $linestart ); $text = $this->unstrip( $text, $this->mStripState ); + # Clean up special characters + $fixtags = array( + "/
/i" => '
', + "/
/i" => '
', + "/
/i"=>'', + "/<\\/center *>/i" => '', + # Clean up spare ampersands; note that we probably ought to be + # more careful about named entities. + '/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/' => '&' + ); + $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text ); $this->mOutput->setText( $text ); wfProfileOut( $fname ); @@ -488,20 +499,6 @@ class Parser $sk =& $this->mOptions->getSkin(); $text = $sk->transformContent( $text ); - $fixtags = array( - "/
/i" => '
', - "/
/i" => '
', - "/
/i"=>'', - "/<\\/center *>/i" => '' - ); - $text = preg_replace( array_keys($fixtags), array_values($fixtags), $text ); - - # Clean up spare ampersands; note that we probably ought to be - # more careful about named entities. - $text = preg_replace( - '/&(?!:amp;|#[Xx][0-9A-fa-f]+;|#[0-9]+;|[a-zA-Z0-9]+;)/', - '&', - $text ); $text .= $this->categoryMagic () ; @@ -1039,12 +1036,11 @@ class Parser # and making lists from lines starting with * # : etc. # $a = explode( "\n", $text ); - $lastPref = $text = $lastLine = ''; - $this->mDTopen = $inBlockElem = false; + $lastPref = $text = ''; + $this->mDTopen = $inBlockElem = $pstack = false; if ( ! $linestart ) { $text .= array_shift( $a ); } foreach ( $a as $t ) { - if ( "" != $text ) { $text .= "\n"; } $oLine = $t; $opl = strlen( $lastPref ); @@ -1052,9 +1048,10 @@ class Parser $pref = substr( $t, 0, $npl ); $pref2 = str_replace( ";", ":", $pref ); $t = substr( $t, $npl ); - + // list generation if ( 0 != $npl && 0 == strcmp( $lastPref, $pref2 ) ) { $text .= $this->nextItem( substr( $pref, -1 ) ); + if ( $pstack ) { $pstack = false; } if ( ";" == substr( $pref, -1 ) ) { $cpos = strpos( $t, ":" ); @@ -1066,6 +1063,7 @@ class Parser } } else if (0 != $npl || 0 != $opl) { $cpl = $this->getCommon( $pref, $lastPref ); + if ( $pstack ) { $pstack = false; } while ( $cpl < $opl ) { $text .= $this->closeList( $lastPref{$opl-1} ); @@ -1090,7 +1088,7 @@ class Parser } $lastPref = $pref2; } - if ( 0 == $npl ) { # No prefix--go to paragraph mode + if ( 0 == $npl ) { # No prefix (not in list)--go to paragraph mode $uniq_prefix = UNIQ_PREFIX; // XXX: use a stack for nestable elements like span, table and div $openmatch = preg_match("/(closeParagraph(); if ( $closematch ) { $inBlockElem = false; @@ -1106,25 +1105,44 @@ class Parser } } else if ( !$inBlockElem ) { if ( " " == $t{0} ) { - $newSection = "pre"; + // pre if ($this->mLastSection != 'pre') { - $text .= $this->closeParagraph(); - $text .= "<" . $newSection . ">"; - $this->mLastSection = $newSection; + $pstack = false; + $text .= $this->closeParagraph().'
';
+							$this->mLastSection = 'pre';
 						}
 					} else { 
-						$newSection = "p";
-						if ( ''==trim($t) && ( '' != trim($lastLine) )) {
-							$text .= $this->closeParagraph();
-							$text .= "<" . $newSection . ">";
-							$this->mLastSection = $newSection;
-						}			
+						// paragraph
+						if ( '' == trim($t) ) {
+							if ( $pstack ) {
+								$text .= $pstack.'
'; + $pstack = false; + $this->mLastSection = 'p'; + } else { + if ($this->mLastSection != 'p' ) { + $text .= $this->closeParagraph(); + $this->mLastSection = ''; + $pstack = "

"; + } else { + $pstack = '

'; + } + } + } else { + if ( $pstack ) { + $text .= $pstack; + $pstack = false; + $this->mLastSection = 'p'; + } else if ($this->mLastSection != 'p') { + $text .= $this->closeParagraph().'

'; + $this->mLastSection = 'p'; + } + } } - } } - $lastLine = $t; - $text .= $t; + if ($pstack === false) { + $text .= $t."\n"; + } } while ( $npl ) { $text .= $this->closeList( $pref2{$npl-1} ); -- 2.20.1